/**
 * PriorityTextData.java
 * 版权所有(C) 2013
 * 创建者:cuiran 2013-11-27 下午12:02:52
 */
package com.ghyf.mplay.net.data;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.Serializable;

import com.ghyf.mplay.net.common.RecvBase;

import android.util.Log;

/**
 *  
 * @author cuiran
 * @version 1.0.0
 */
public class PriorityTextData implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 995774363139280524L;
	public static final int textIDLength =	16;
	public static final int textContentLength =	1024;
	protected String tag = "PriorityTextData";
	protected String UnknownID = "UnknownTextID123";

	public short uid = 0;
	public String textID = new String("");
	public short textLevel = 0;
	public int textStartTime = 0;
	public int textStopTime = 0;
	public String textContent = new String("");
	public short textShowInterval = 0;
	public short textShowTimes = 0;
	
	public PriorityTextData() {	}
	
	public boolean IsInitialed()
	{
		return !(textID.equals(UnknownID));
	}
	
	public boolean GetTextData(byte [] buf_recv, int packetHeaderLength, int setPriorityDataLength)
	{
		ByteArrayInputStream baInPacketData = new ByteArrayInputStream(buf_recv, packetHeaderLength, setPriorityDataLength);
		DataInputStream dInData = new DataInputStream(baInPacketData);
		byte[] buf_temp = new byte[textContentLength];
		
		try
		{
			uid = dInData.readShort();
			dInData.read(buf_temp, 0, textIDLength);
			textID = new String(buf_temp, 0, textIDLength);
			textLevel = dInData.readShort();
			textStartTime = dInData.readInt();
			textStopTime = dInData.readInt();
			dInData.read(buf_temp, 0, textContentLength);
			textContent = new String(buf_temp, 0, textContentLength,RecvBase.charset).trim();
			textShowInterval = dInData.readShort();
			textShowTimes = dInData.readShort();
			dInData.skipBytes(10);
			
			// maybe we should check data validation here!
			// ...
			
			return true;
		}
		catch(IOException e)
		{
			Log.i(tag, "TextData.GetTextData() -- catch IOException: " + e.getLocalizedMessage());
			textID = UnknownID;		// make sure UnInitial
			return false;
		}
		
	}
	
	
	
	/**
	 * @return the uid
	 */
	public short getUid() {
		return uid;
	}

	/**
	 * @param uid the uid to set
	 */
	public void setUid(short uid) {
		this.uid = uid;
	}

	
	/**
	 * @return the textID
	 */
	public String getTextID() {
		return textID;
	}

	/**
	 * @param textID the textID to set
	 */
	public void setTextID(String textID) {
		this.textID = textID;
	}

	/**
	 * @return the textLevel
	 */
	public short getTextLevel() {
		return textLevel;
	}

	/**
	 * @param textLevel the textLevel to set
	 */
	public void setTextLevel(short textLevel) {
		this.textLevel = textLevel;
	}

	/**
	 * @return the textShowInterval
	 */
	public short getTextShowInterval() {
		return textShowInterval;
	}

	/**
	 * @param textShowInterval the textShowInterval to set
	 */
	public void setTextShowInterval(short textShowInterval) {
		this.textShowInterval = textShowInterval;
	}

	/**
	 * @return the textShowTimes
	 */
	public short getTextShowTimes() {
		return textShowTimes;
	}

	/**
	 * @param textShowTimes the textShowTimes to set
	 */
	public void setTextShowTimes(short textShowTimes) {
		this.textShowTimes = textShowTimes;
	}

	/**
	 * @return the textStartTime
	 */
	public int getTextStartTime() {
		return textStartTime;
	}

	/**
	 * @param textStartTime the textStartTime to set
	 */
	public void setTextStartTime(int textStartTime) {
		this.textStartTime = textStartTime;
	}

	/**
	 * @return the textStopTime
	 */
	public int getTextStopTime() {
		return textStopTime;
	}

	/**
	 * @param textStopTime the textStopTime to set
	 */
	public void setTextStopTime(int textStopTime) {
		this.textStopTime = textStopTime;
	}

	/**
	 * @return the textContent
	 */
	public String getTextContent() {
		return textContent;
	}

	/**
	 * @param textContent the textContent to set
	 */
	public void setTextContent(String textContent) {
		this.textContent = textContent;
	}

	public String toString()
	{
		return  new String("uid=" + uid + " Level=" + textLevel + " StartTime=" + textStartTime + " StopTime=" + textStopTime + " ShowInterval=" 
				+ textShowInterval + " ShowTimes=" + textShowTimes + " textID=" + textID + " Content=" + textContent);
	}
}
